import requests
import subprocess
from functools import partial
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
import time
with open("参数加密.js", "r", encoding="utf-8") as f:
    data = f.read()
js = execjs.compile(data)
headers = {
    "authority": "www.qcc.com",
    "a48256cb444e5ca8def0": "de33bd3b87eba5b23db21c8b5b55b7017a0edcc8720dd31b0fe012ac225b4c59ae049e921ea5483e052e10dc437accdb5d2a8502d3e603763be4fcc676ae28e4",
    "accept": "application/json, text/plain, */*",
    "accept-language": "zh-CN,zh;q=0.9",
    "referer": "https://www.qcc.com/",
    "sec-ch-ua": "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
    "x-pid": "52c4cbefe536befc5f9743c831e7f6c5",
    "x-requested-with": "XMLHttpRequest"
}
cookies = {
    "qcc_did": "2408b198-f08e-4c20-887b-8e1582cbe362",
    "UM_distinctid": "18ad105a43d7cc-02c4f9cdf25716-26031e51-144000-18ad105a43e13dc",
    "QCCSESSID": "c57426f9c211436bba436af4c0",
    "CNZZDATA1254842228": "282867247-1695723922-https%253A%252F%252Fwww.baidu.com%252F%7C1706239356"
}
print(str(int(time.time()*1000)))
url = f"https://www.qcc.com/api/home/getNewsFlash?firstRankIndex=&lastRankIndex={str(int(time.time()*1000))}&lastRankTime={str(int(time.time()*1000))}&pageSize=10"

base_url = "/" + url.split("/", 3)[3]
data = js.call("result", base_url)
key = data["i"]
values = data["l"]
headers[key] = values
response = requests.get(url, headers=headers, cookies=cookies)

print(response.json())
print(response)
